package com.yunji.ylexpiration.service.impl;

import com.yunji.ylexpiration.entity.FurnUser;
import com.yunji.ylexpiration.entity.FurnUserExample;
import com.yunji.ylexpiration.mapper.FurnUserMapper;
import com.yunji.ylexpiration.service.RegisterService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class Registerimpl implements RegisterService {
    @Resource
    private FurnUserMapper furnUserMapper;
    @Override
    public FurnUser login(String account, String paw) {
        FurnUserExample furnUserExample=new FurnUserExample();
        FurnUserExample.Criteria criteria=furnUserExample.createCriteria();
        criteria.andUserAccountEqualTo(account);
        List<FurnUser>list=furnUserMapper.selectByExample(furnUserExample);
        if (list==null|| list.size()==0){
            return null;
        }
        FurnUser furnUser=list.get(0);
        if (!paw.equals(furnUser.getUserPassword())){
            return null;
        }
        return furnUser;
    }

    @Override
    public int insertSelective(FurnUser record) {
         int addaccount=furnUserMapper.insertSelective(record);
        return addaccount;
    }

    @Override
    public FurnUser selectByuserid(Integer userId) {
        FurnUserExample example = new FurnUserExample();
        FurnUserExample.Criteria criteria = example.createCriteria();
        criteria.andIdEqualTo(userId);
        List<FurnUser> furnUsers = furnUserMapper.selectByExample(example);
        if(furnUsers==null||furnUsers.size()==0){
            return null;
        }
        return furnUsers.get(0);
    }

    @Override
    public int updateByimgtx(FurnUser furnUser) {
        int i = furnUserMapper.updateByPrimaryKeySelective(furnUser);
        return i;
    }
    @Override
    public int updateByPrimaryKeySelective(FurnUser record) {
        int upcout=furnUserMapper.updateByPrimaryKeySelective(record);
        return upcout;
    }
}
